home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: bob_m@ix.netcom.com(Bob M )
- Newsgroups: comp.lang.c++
- Subject: References & Pointers in Borland C++
- Date: 11 Mar 1996 21:39:49 GMT
- Organization: Netcom
- Message-ID: <4i26j5$roe@dfw-ixnews3.ix.netcom.com>
- NNTP-Posting-Host: har-ct7-19.ix.netcom.com
- X-NETCOM-Date: Mon Mar 11 3:39:49 PM CST 1996
-
- I am trying to understand the concept of "References".
-
- But a couple of things are confusing me.
-
- 1.
- The Programmer's manuals for Borland Turbo C++ version 1.01 (1990)
- and Borland C++ version 4.02 describe in nearly identical text, that
- it is acceptable to initialize a Reference with a specific number:
- int& ir = 6;
- Both my 3.1 and 4.02 compilers reject this with an error: "Reference
- initialized with 'int' needs lvalue of type 'int'".
- Which is right, the compiler or the book?
-
- 2.
- Using the Inspector window in the Debugger, I could see that a
- Reference appears identical to a pointer, except that the compiler
- insists that you initialize it to some selected variable.
- It looks as though one should be able to assign a "filled in"
- pointer to a reference, as follows:
- int num, nother;
- int &ref1 = num, &ref2 = nother;
- int *ptr1;
-
- ptr1 = &ref1; // sets the pointer to the same address as "num".
- &ref2 = ptr1; // Change &ref2 to point at "num".
-
- The first assignment is apparently legal, but the second depends
- on the version of the compiler. 3.1 accepts it, while 4.01 says:
- "Lvalue required in function main".
- Should this be legal?
-
-
-
-
-
-
-